package com.example.video.common.util;

import com.example.video.HCNetSDK;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class HikUtils {



    /**
     * 获取海康录像机格式的时间
     *
     * @param time
     * @return
     */
    public static HCNetSDK.NET_DVR_TIME getHkTime(LocalDateTime time) {
        HCNetSDK.NET_DVR_TIME structTime = new HCNetSDK.NET_DVR_TIME();

        String str = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(time);
        String[] times = str.split("-");
        structTime.dwYear = Integer.parseInt(times[0]);
        structTime.dwMonth = Integer.parseInt(times[1]);
        structTime.dwDay = Integer.parseInt(times[2]);
        structTime.dwHour = Integer.parseInt(times[3]);
        structTime.dwMinute = Integer.parseInt(times[4]);
        structTime.dwSecond = Integer.parseInt(times[5]);
        return structTime;
    }

    /**
     * 获取海康录像机格式的时间
     *
     * @param time
     * @return
     */
    public static HCNetSDK.NET_DVR_TIME getHkTime(String time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(time, formatter);
        return getHkTime(parse);
    }

    public static HCNetSDK.NET_DVR_TIME_V30 getHkTimeV30(String time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(time, formatter);
        return getHkTimeV30(parse);
    }

    /**
     * 获取海康录像机格式的时间
     *
     * @param time
     * @return
     */
    public static HCNetSDK.NET_DVR_TIME_V30 getHkTimeV30(LocalDateTime time) {
        HCNetSDK.NET_DVR_TIME_V30 structTime = new HCNetSDK.NET_DVR_TIME_V30();

        String str = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(time);
        String[] times = str.split("-");
        structTime.wYear = Short.parseShort(times[0]);
        structTime.byMonth = Byte.parseByte(times[1]);
        structTime.byDay = Byte.parseByte(times[2]);
        structTime.byHour = Byte.parseByte(times[3]);
        structTime.byMinute = Byte.parseByte(times[4]);
        structTime.bySecond = Byte.parseByte(times[5]);
        return structTime;
    }
}
